<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>公告管理</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">

    <#assign currentMenu="salary"/>

    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>公告管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/announcement/list" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label>创建日期查询：</label>
                        <input placeholder="请输入开始日期" type="text"  class="form-control xxx" name="startTime" value="${(qo.startTime?string('yyyy-MM-dd'))!}" /> -
                        <input placeholder="请输入结束日期" type="text"  class="form-control xxx" name="endTime" value="${(qo.endTime?string('yyyy-MM-dd'))!}" />
                    </div>

                    <div class="form-group">
                        <label > 阅读状态:</label>
                        <select class="form-control" name="status">
                            <option value="">全部</option>
                            <option value="0">未发布</option>
                            <option value="1">已发布</option>
                        </select>
                    </div>
                    <script>
                        $("select[name=status]").val(${(qo.status?string('1','0'))!})
                    </script>
                    <div class="form-group">
                        <label > 公告级别:</label>
                        <select class="form-control" name="level">
                            <option value="">请选择级别</option>
                            <#list values as v>
                                <option value="${v.getValue()}">${v.getName()}</option>
                            </#list>
                        </select>
                        <script>
                            $("select[name=level]").val(${qo.level})
                        </script>
                    </div>

                    <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                    <#if (EMP_IN_SESSION.name! == 'admin')>
                        <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </#if>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive">
                    <table class="table table-hover table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>公告标题</th>
                            <th>创建人</th>
                            <th>创建时间</th>
                            <th>公告级别</th>
                            <th>是否已读</th>
                            <th>发布状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list pageInfo.list as a>
                            <#if (EMP_IN_SESSION.name! == 'admin') || (a.status)>
                                <tr>
                                    <td>${a_index+1}</td>
                                    <td>${a.title}</td>
                                    <td>${a.createPerson.name}</td>
                                    <td>${(a.createTime?string('yyyy-MM-dd HH:mm:ss'))!}</td>
                                    <td>${a.levelName}</td>
                                    <td>${(a.ifread?string('已读','未读'))!}</td>
                                    <td>${(a.status?string('已发布','未发布'))!}</td>
                                    <td>
                                        <a href="/content/index?id=${a.id}" class="btn btn-success btn-xs">
                                            <span class="glyphicon glyphicon-pencil"></span> 查看
                                        </a>

                                        <#if (EMP_IN_SESSION.name! == 'admin')>
                                            <a href="#" class="btn btn-primary btn-xs btn-input" data-json='${a.toJson()}'>
                                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                                            </a>
                                            <a href="/announcement/change?status=${(a.status?string('true','false'))!}&id=${a.id}" class="btn btn-${(a.status?string('danger','info'))!} btn-xs change" data-json='${a.toJson()}'>
                                                <span class="glyphicon glyphicon-pencil"></span> ${(a.status?string('取消','发布'))!}
                                            </a>
                                        </#if>
                                    </td>
                                </tr>
                            </#if>

                        </#list>
                        </tbody>
                    </table>
                    <#include "/common/page.ftl" >
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl" >
</div>
<script>
    $(".xxx").datetimepicker({
        format:'yyyy-mm-dd', //格式
        language:'zh-CN', //中文
        autoclose: true,//选择后自动关闭
        //showMeridian:true, //是否显示上下午
        minView:2,//精确到哪位
    });
</script>

<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <form class="form-horizontal" action="/announcement/saveOrUpdate" method="post" id="editForm">
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">公告标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title"
                                   placeholder="请输入公告标题">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">公告内容：</label>
                        <div class="col-sm-6">
                            <textarea type="text" class="form-control" rows="8" name="content"
                                   placeholder="请输入公告内容"></textarea>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">公告级别：</label>
                        <div class="col-sm-6">
                            <select type="text" class="form-control" id="level" name="level">
                                <option value="">请选择级别</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $.post("/announcement/listLevels",function (data) {
        let str = '<option value="">请选择级别</option>'
         console.log(data);
        $.each(data,function (index,ele) {
            console.log(ele);

            str += '<option value="'+index+'">'+ele+'</option>'
        })
        $("#level").html(str)
    })


    $(".btn-input").click(function () {
        //删除回显数据
        $("input").val('')
        $("textarea").html('')
        $("select[name='level']").val('')

        let json = $(this).data("json")
        if(json){
            $("input[name='id']").val(json.id)
            $("input[name='title']").val(json.title)
            $("textarea[name='content']").val(json.content)
            $("select[name='level']").val(json.level)
        }

        $("#editModal").modal("show")
    })
</script>
</body>
</html>
